<template>
	<view class="list-page" :style="loading ? 'opacity: 0;' : 'opacity: 1;'">
		<!--  v-model="dataList" @query="queryList" -->
		<!--  refresher-only @onRefresh="onRefresh" -->
		<pageTxt>
			<listTabCom class="listTabCom" :tabList="topTabListArr" @topTabClick="topTabClick" :current="topTabIndex"></listTabCom>
			<!-- 客户管理 -->
			<customerManagement ref="customerManagement" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 1"></customerManagement>
			<!-- 项目管理 -->
			<projectManagement ref="projectManagement" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 2"></projectManagement>
			<!-- 合同管理 -->
			<contractManagement ref="contractManagement" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 3"></contractManagement>
			<!-- 对客日志 -->
			<customerLog ref="customerLog" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 4"></customerLog>
			<!-- 优惠审批 -->
			<discountApproval ref="discountApproval" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 5"></discountApproval>
			<!-- 项目评分 -->
			<projectRating ref="projectRating" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 6"></projectRating>
		</pageTxt>
	</view>
</template>

<script>
import customerManagement from './components/customerManagement/customerManagement.vue';
import projectManagement from './components/projectManagement/projectManagement.vue';
import contractManagement from './components/contractManagement/contractManagement.vue';
import customerLog from './components/customerLog/customerLog.vue';
import discountApproval from './components/discountApproval/discountApproval.vue';
import projectRating from './components/projectRating/projectRating.vue';
export default {
	components: {
		customerManagement,
		projectManagement,
		contractManagement,
		customerLog,
		discountApproval,
		projectRating
	},
	data() {
		return {
			loading: true,
			dataList: [],
			conentHeight: 0,
			topTabIndex: '-1',
			showIndex: 0,
			topTabList: [
				{
					name: '客户管理',
					menu: '/khgl',
					key: 1
				},
				{
					name: '项目管理',
					menu: '/xmgl',
					key: 2
				},
				{
					name: '合同管理',
					menu: '/htgl',
					key: 3
				},
				{
					name: '对客日志',
					menu: '/dkrz',
					key: 4
				},
				{
					name: '优惠审批',
					menu: '/yhgl',
					key: 5
				},
				{
					name: '项目评分',
					menu: '/xmpf',
					key: 6
				}
			],
			topTabListArr: []
		};
	},
	onLoad(option) {
		this.getHeight();
		// 菜单权限判断
		let topTabListArr = [];
		this.topTabList.forEach((item) => {
			if (this.$menuShow(item.menu)) {
				topTabListArr.push(item);
			}
		});
		this.topTabListArr = topTabListArr;
		this.$nextTick(() => {
			if (option.tabIndex) {
				let index = topTabListArr.findIndex((item) => {
					return item.key == option.tabIndex;
				});
				this.topTabIndex = index;
				this.showIndex = option.tabIndex;
			}
		});
	},
	onShow() {
		// 更新单条数据
		this.$nextTick(() => {
			switch (Number(this.showIndex)) {
				case 1:
					if (!this.$refs.customerManagement) return;
					this.$refs.customerManagement.refreshItemFunc();
					break;
				case 2:
					if (!this.$refs.projectManagement) return;
					this.$refs.projectManagement.refreshItemFunc();
					break;
				case 3:
					if (!this.$refs.contractManagement) return;
					this.$refs.contractManagement.refreshItemFunc();
					break;
				case 4:
					// this.$refs.customerLog.refreshItemFunc();
					break;
				case 5:
					if (!this.$refs.discountApproval) return;
					this.$refs.discountApproval.refreshItemFunc();
					break;
				case 6:
					// this.$refs.projectRating.refreshItemFunc();
					break;
				default:
			}
		});
	},
	methods: {
		getHeight(index) {
			// 创建节点查询
			let that = this;
			const systemInfo = uni.getSystemInfoSync();
			const query = uni.createSelectorQuery().in(that);
			query.select('.listTabCom').boundingClientRect();
			query.exec((res) => {
				that.conentHeight = systemInfo.screenHeight - (res[0].height + 20); //组件可用高度 20状态栏高度（动态获取高度不包含状态栏高度）
				setTimeout(() => {
					that.loading = false;
				}, 200);
			});
		},
		topTabClick(index) {
			this.topTabIndex = index;
			this.showIndex = this.topTabListArr[index].key;
		}
	}
};
</script>

<style lang="scss" scoped>
@import 'saleManagement.scss';
</style>
